package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.common.domain.query.PageQuery;
import com.tianji.learning.domain.dto.LearningPlanDTO;
import com.tianji.learning.domain.vo.LearningLessonVO;
import com.tianji.learning.domain.vo.LearningPlanPageVO;
import com.tianji.learning.service.ILearningLessonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 学生课程表 前端控制器
 * </p>
 *
 * @author dayu
 * @since 2024-08-20
 */
@RestController
@RequestMapping("/lessons")
@Api(tags = "学习相关接口")
public class LearningLessonController {

  @Autowired
  private ILearningLessonService learningLessonService;

  @ApiOperation("")
  @GetMapping("page")
  public PageDTO<LearningLessonVO> queryMyOrderPage(PageQuery pageQuery) {
    return learningLessonService.queryMyLearningLessonPage(pageQuery);
  }

  @ApiOperation("")
  @GetMapping("now")
  public LearningLessonVO now() {
    return learningLessonService.now();
  }

  @ApiOperation("")
  @DeleteMapping("{courseId}")
  public void delRefundCourse(@PathVariable Long courseId) {
    learningLessonService.delRefundCourse(courseId);
  }

  @ApiOperation("")
  @GetMapping("{courseId}/valid")
  public Long isLessonValid(@PathVariable Long courseId) {
    return learningLessonService.isLessonValid(courseId);
  }
  @ApiOperation("")
  @GetMapping("{courseId}")
  public LearningLessonVO getCourse(@PathVariable Long courseId) {
  return   learningLessonService.getCourse(courseId);
  }
  @ApiOperation("")
  @GetMapping("{courseId}/count")
  public Integer countLearningLessonByCourse(@PathVariable("courseId") Long courseId){
  return   learningLessonService.countLearningLessonByCourse(courseId);
  }

  @ApiOperation("创建学习计划")
  @PostMapping("/plans")
  public void createLearningPlans(@Valid @RequestBody LearningPlanDTO planDTO){
    learningLessonService.createLearningPlan(planDTO.getCourseId(), planDTO.getFreq());
  }

  @ApiOperation("查询我的学习计划")
  @GetMapping("/plans")
  public LearningPlanPageVO queryMyPlans(PageQuery query){
    return learningLessonService.queryMyPlans(query);
  }

}
